<template>
  <div>
    <div>姓名: <input type="text" v-model="name" /></div>
    <div>年龄: <input type="number" v-model="age" /></div>
    <div>身高: <input type="number" v-model="height" />(米)</div>
    <div>体重: <input type="number" v-model="weight" />(公斤)</div>
    <div>病史: <input type="text" v-model="sick" /></div>
    <button @click="add">诊断</button>
    <div v-if="result">患者{{ name }}的诊断结果{{ result }}</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      age: 0,
      height: 0,
      weight: 0,
      sick: "",
      result: "",
    };
  },
  methods: {
    add() {
      const BMI = this.weight / (this.height  * this.height)
      if (BMI <= 18.5) {
        this.result = "体重过轻"
      } else if (18.5 < BMI && BMI <= 24.9) {
        this.result = "正常"
      } else if (24.9 < BMI && BMI <= 29.9) {
        this.result = "体重过重"
      } else {
        this.result = "肥胖"
      }
    },
  },
};
</script>
